package com.example.NeteaseCloudMusicApi.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.NeteaseCloudMusicApi.R;
import com.example.NeteaseCloudMusicApi.entity.My;
import com.example.NeteaseCloudMusicApi.ui.adapter.FoundAdapter;
import com.example.NeteaseCloudMusicApi.ui.adapter.MyAdapter;
import com.example.NeteaseCloudMusicApi.ui.adapter.RecommendSongListAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MyFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MyFragment extends Fragment {

    RecyclerView recyclerView;
    LinearLayoutManager layoutManager;
    MyAdapter adapter;
    View rootView;
    private List<My> mMy = new ArrayList<My>();

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public MyFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment MyFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static MyFragment newInstance(String param1, String param2) {
        MyFragment fragment = new MyFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_my, container, false);
        initMy();
        return rootView;


    }

    private void initMy() {
        My my1 = new My("本地/下载", R.mipmap.local_download);
        mMy.add(my1);
        My my2 = new My("云盘", R.mipmap.yun_file);
        mMy.add(my2);
        My my3 = new My("已购", R.mipmap.bought);
        mMy.add(my3);
        My my4 = new My("最近播放", R.mipmap.latest_play);
        mMy.add(my4);
        My my5 = new My("我的好友", R.mipmap.my_friends);
        mMy.add(my5);
        My my6 = new My("收藏和赞", R.mipmap.collect);
        mMy.add(my6);
        My my7 = new My("我的播客", R.mipmap.my_boke);
        mMy.add(my7);
        My my8 = new My("音乐应用", R.mipmap.music_app);
        mMy.add(my8);

        recyclerView = rootView.findViewById(R.id.recyclerview_my);
        layoutManager = new GridLayoutManager(getContext(), 4);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new MyAdapter(mMy);
        recyclerView.setAdapter(adapter);
    }
}